package com.example.waterrecordopengl;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.gushen.library.MySurfaceView;
import com.gushen.library.RecorderCallBack;
import com.gushen.library.WatermarkConfig;
import com.gushen.library.utils.FileUtils;


public class MainActivity extends AppCompatActivity {
    private View waterMarkView;
    private Bitmap waterMarkBitmap;
    private MySurfaceView mySurface;


    @Override
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mySurface = findViewById(R.id.continuousRecord_surfaceView);
        waterMarkView = findViewById(R.id.water_mark_view);
        waterMarkView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                waterMarkView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                waterMarkBitmap = FileUtils.createWaterMark(waterMarkView);

                WatermarkConfig watermarkConfig = new WatermarkConfig();
                watermarkConfig.setBitmapWatermark(waterMarkBitmap);

                watermarkConfig.setWaterMarkType(WatermarkConfig.WATERMARK_TYPE_TEXT);
                watermarkConfig.setTextColor(Color.WHITE);
                watermarkConfig.setTextWatermark("你啊辣斗辣快递费久啊代发,\n阿萨德卡拉兹,\n54654123468786843545463,\nfhfytrtylkjkjhkjhsesrtuuioonhjg");

                mySurface.setWatermarkConfig(watermarkConfig);
            }
        });

        Button recordButton = findViewById(R.id.btn_record);
        recordButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mySurface.startRecord();
            }
        });

        findViewById(R.id.btn_stop_record).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               mySurface.stopRecord(new RecorderCallBack() {

                   @Override
                   public void onRecorderCallBack(String localVideoPath) {
                       //录制完成
                       Toast.makeText(MainActivity.this, "录制完成,保存地址："+localVideoPath, Toast.LENGTH_SHORT).show();
                   }

               });
            }
        });
    }

}
